package com.neusoft.service.serviceimpl;

import com.neusoft.mapper.CommentMapper;
import com.neusoft.po.Comment;
import com.neusoft.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RefreshScope
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Boolean createComment(String userId, Integer businessId, String comment, Integer rank) {
        Comment commentObj = new Comment(userId, businessId, comment, rank, null);
        return commentMapper.createComment(commentObj);
    }

    @Override
    public List<Comment> getCommentByBusinessId(Integer businessId) {
        return commentMapper.getCommentByBusinessId(businessId);
    }

    @Override
    public List<Comment> getCommentByUserId(String userId) {
        return commentMapper.getCommentByUserId(userId);
    }

    @Override
    public Boolean updateComment(Integer commentId, String comment, Integer rank) {
        Comment commentObj = new Comment();
        commentObj.setcommentId(commentId);
        commentObj.setComment(comment);
        commentObj.setRank(rank);
        System.out.println(commentObj.getRank());
        return commentMapper.updateComment(commentObj);
    }
}